/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AdminAddManager;


import java.sql.*;
import DBManager.DBConnection;
import java.util.Date;

/**
 *
 * @author Alex
 */
public class AdminAddManager {
    public boolean addManager(Manager newManager)
    {
        boolean result = false;
        
        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();
            
          
            PreparedStatement pstmt =
                conn.prepareStatement("insert into manager(username,password,lastname,firstname,middlename,type)"
                    + "values (?,?,?,?,?,?)");
            
            //append values for the parameters
            int i = 1;
            pstmt.setString(i++, newManager.getUsername());
            pstmt.setString(i++, newManager.getPassword());
              pstmt.setString(i++, newManager.getLastname());
            pstmt.setString(i++, newManager.getFirstname());
            pstmt.setString(i++, newManager.getMiddle());
                pstmt.setString(i++, newManager.getType());

            //execute SQL statement
            pstmt.executeUpdate();
            
            result = true;
        }
        catch(SQLException ex){ex.printStackTrace();}
        
        return result;
    }
    
     public int Log(int x,Manager addmanager)
    { Date newDate = new java.util.Date();
       int result=0;
        
        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn =  db.getConnection();
             java.util.Date time = new java.util.Date();
             
        
                   String message="Added Manager date"+newDate + "\n"+ "Added"+
                           "\n"+ addmanager.getUsername()+ "\n";
                   String message1="\nAdded Manager time:"+time;
          
            PreparedStatement pstmt =  conn.prepareStatement("insert into logadmin(adminid,message) values(?,?)");
            
            //append values for the parameters
            int i = 1;
            pstmt.setInt(i++, x);
            pstmt.setString(i++, message);
           
            pstmt.executeUpdate();
result=1;
            //execute SQL statement
         
          
        }
        catch(SQLException ex){ex.printStackTrace();}
        
        return result;
    }    
}
